<template>
  <div class="edit">
    <el-card class="box-card">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="上传图片" prop="startUrl">
          <Upload v-model="form.startUrl" @clear="clearImageValidate" />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm">确定</el-button>
          <el-button @click="cancel">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
import Upload from "@/components/Upload";
import { getAppStart, saveAppStart } from "@/api/system/appStart";

export default {
  name: "AppStart",
  components: {
    Upload
  },
  data() {
    return {
      // 表单参数
      form: {
        startUrl: ""
      },
      // 表单校验
      rules: {
        startUrl: [{ required: true, message: "请上传图片" }]
      }
    };
  },
  mounted() {
    this.getEditInfo();
  },
  methods: {
    clearImageValidate() {
      this.rules.startUrl = [];
      this.$refs["form"].clearValidate("startUrl");
    },
    getEditInfo() {
      getAppStart().then(response => {
        this.form = response.data;
      });
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          saveAppStart(this.form).then(response => {
            if (response.code === 200) {
              this.msgSuccess("修改成功");
            }
          });
        }
      });
    },
    // 重置按钮
    cancel() {
      this.getEditInfo();
      this.resetForm("form");
    }
  }
};
</script>
